<template>
	<view class="pages header-bg">
		<!-- 顶部导航栏-开始 -->
		<view class="cu-custom" :style="[{ height: CustomBar + 'px' }]">
			<view class="cu-bar fixed header-bg text-white"
				:style="{height: CustomBar+'px',paddingTop: StatusBar+'px'}">
				<view class="action" @tap="back()">
					<text class="cuIcon-back"></text>
				</view>
				<view class="content" :style="[{top:StatusBar+'px'}]">{{ i18n['订单详情'] }}</view>
			</view>
		</view>
		<!-- 顶部导航栏-结束 -->
		<!-- 订单状态-开始 -->
		<!-- 订单状态-开始 -->
		<!-- order_type 3普通订单 4积分订单 5拼团订单 6秒杀订单 7预售订单 -->
		<view class="flex align-center justify-between padding-lr-lg"
			v-if="isContentShow([3,4,6,10], model.order_type)">
			<view class="text-white fu-fs24">
				<view class="fu-fs32 text-bold" v-if="select_way_num == 1">{{ model.status | statusFil }}</view>
				<view class="fu-fs32 text-bold" v-else>{{ model.status | inviteStatusFil }}</view>
				<view class="margin-top-xs" v-if="model.status == 0">{{ i18n['剩余时间'] }}:
					{{ downTime.hours }}:{{ downTime.minutes }}:{{ downTime.seconds }}
				</view>
				<view class="margin-top-xs" v-if="model.status == 2">
					{{ i18n['还剩'] }}{{ downTime.days }}{{i18n['天']}}{{ downTime.hours }}时{{ downTime.minutes }}分自动确认
				</view>
				<!-- <view class="margin-top-xs" v-if="model.status == 3">
					{{i18n["您的评价将会给其他买家参考"]}}
				</view> -->
			</view>
			<image class="fu-block-140" src="https://localelife.chunchuangkeji.cn/h5img/images/status_1.png" mode="aspectFit"></image>
		</view>
		<!-- 订单状态-结束 -->
		<fu-loading v-if="isShowLoading"></fu-loading>
		<view class="" v-else>
			<!-- 收货地址-开始 -->
			<!-- <view class="bg-white flex align-center padding-lr-sm padding-tb-lg margin-lr-sm radius-16"
				v-if="select_way_num == 1">
				<image class="fu-block-60 round margin-right-sm" :src="imgBaseUrl + 'order/address.png'" mode="aspectFill"></image>
				<view class="flex align-center justify-between flex-sub" style="min-width: 1px;">
					<view class="flex-sub" style="min-width: 1px;">
						<view class="flex align-center text-333 text-bold">
							<view class="margin-right-xs  radius-8 solid   padding-lr-xs fu-fs20 " style="border: 1rpx solid #698BFF;background: #F3F6FF;color:#698BFF ;" v-if="model.order_info.label_name">{{ model.order_info.label_name }}</view>
							<view class="text-cut fu-fs32 text-bold text-333" style="min-width: 1px;max-width: 150rpx;">
								{{ model.order_info.receiver_name }}
							</view>
							<text class="margin-left fu-fs32">{{ model.order_info.receiver_mobile | filterMobile }}</text>
						</view>
						<view class="margin-top-sm text-333 fu-fs24">
							{{ model.order_info.province + ' ' + model.order_info.city + ' ' + model.order_info.district + ' ' + model.order_info.receiver_address }}
						</view>
					</view>
					<view class="cuIcon-right"></view>
				</view>
			</view> -->
			<!-- 收货地址-结束 -->

			<!-- 商品和金额信息-开始 -->
			<view class="center-box bg-white margin-lr-sm radius-8 margin-top-sm">
				<view class="">
					<!-- 店铺信息 -->
					<view class="shop-box flex align-center" v-if="model.shop_info">
						<image src="https://localelife.chunchuangkeji.cn/h5img/images/009.png" class="fu-block-32 margin-right-16"></image>
						<view class="name text-666 fu-fs28">{{model.shop_info.store_name}}</view>
					</view>
					<view style="padding: 0 32rpx 32rpx;">
						<view class="show">
							<block v-for="(item, index) in model.order_goods_list" :key="index">
								<view class="goods-box padding-tb-32">
									<view class="flex align-stretch" @click="navToDetail(item)">
										<view class="fu-block-140 margin-right-24 relative">
											<fu-image radius="16" :src="item.goods_thumb" mode="aspectFill"></fu-image>
											<!-- <view class="iconBox bg-red text-white padding-lr-xs" v-if="model.order_type==10">抢购
											</view> -->
										</view>
										<view class="flex-sub flex flex-direction justify-between" style="min-width: 1px;">
											<view>
												<view class="text-333 fu-fs28 text-cut text-bold">{{ item.goods_name }}</view>
												<!-- {{ item.sku_name }} -->
												<view class="flex align-center margin-top-16">
													<view class="flex align-center margin-right-48">
														<image src="https://localelife.chunchuangkeji.cn/h5img/images/007.png" class="fu-block-22 margin-right-6"></image>
														<text class="text-666 fu-fs20" v-if="item.is_appointment">需要预约</text>
														<text class="text-666 fu-fs20" v-else>无需预约</text>
													</view>
													<view class="flex align-center">
														<image src="https://localelife.chunchuangkeji.cn/h5img/images/008.png" class="fu-block-22 margin-right-6"></image>
														<text class="text-666 fu-fs20">{{item.business_hours}}</text>
													</view>
												</view>
											</view>
											<view class="flex align-center justify-between">
												<view>
													<text class="text-prices text-bold" style="color: #FF5C5C;">
														<text class="text-price">{{item.shop_price}}</text>
													</text>
													<text class="margin-left-16 text-999 fu-fs20 text-through">
														¥{{item.market_price}}
													</text>
												</view>
												<text class="text-999 fu-fs24">x{{item.num}}</text>
											</view>
										</view>
									</view>
									<!-- <view class="flex align-center justify-end"
										v-if="model.order_type != 5  && model.order_type != 7 && model.order_type != 10">
										<view
											class="round width-200 height-56 line-height-56 fu-fs24 text-center bg-f6 text-333 btn margin-top-sm"
											@click.stop="toAfterOrderDetails(item, index)" v-if="item.refund_id > 0">
											{{ i18n['查看售后详情'] }}
										</view>
										<view
											class="round width-144 height-56 line-height-56 fu-fs24 text-center bg-f6 text-333 btn margin-top-sm"
											@click.stop="toAftermarket(item, index)"
											>
											{{ i18n['申请售后'] }}
										</view>
									</view> -->
									<!-- <view class="hxm text-666 fu-fs24" v-if="model.status == 1&&model.is_goods_type == 2">核销码：{{model.picke_code}}</view> -->
									<view class="hxm text-666 fu-fs24" v-if="item.write_off_num">已核销：{{item.write_off_num}}个</view>
								</view>
							</block>
						</view>
						<!-- 核销码 -->
						<view class="hxm text-999 fu-fs24" style="background-color: #F6F7F9;margin-top: 16rpx;" v-if="model.status == 3 || model.status == 4">已核销：<text class="text-through">{{model.picke_code}}</text></view>
						<view class="hx-code flex flex-direction align-center" v-if="model.status == 1">
							<view class="text-333 fu-fs28 text-bold">核销码：{{model.picke_code}}</view>
							<image :src="model.picke_code_img" class="fu-block-280 margin-top-32"></image>
							<!-- <view class="btn margin-top-32" @click="save">保存到相册</view> -->
						</view>
					</view>
				</view>
			</view>
			<!-- 商品和金额信息-结束 -->

			<!-- 订单信息-开始 -->
			<view class="bg-white padding-lr-sm padding-tb margin-lr-sm radius-16 margin-top-sm">
				<view class="title-block text-bold flex align-center fu-fs32 text-blod padding-bottom solid-bottom">
					{{ i18n['订单信息'] }}
				</view>
				<view class="content">
					<!-- <view class="flex fu-fs24 padding-top">
						<view class="text-666 margin-right-lg">{{i18n['订单备注']}}</view>
						<view class="text-333 flex-sub" style="min-width: 1px;">
							{{ model.order_info && model.order_info.remark? model.order_info.remark : i18n['无'] }}
						</view>
					</view> -->
					<view class="flex fu-fs24 padding-top align-center">
						<view class="text-666 margin-right-lg width-144">{{ i18n['订单编号'] }}</view>
						<view class="text-333">
							{{ model.order_sn }}
							<text @click="copyOrderSn(model.order_sn)" style="color: #2F98FE;"
								class="text-vecode margin-left-sm" space="emsp">{{ i18n['复制'] }}</text>
						</view>
					</view>
					<view class="flex fu-fs24 padding-top align-center">
						<view class="text-666 margin-right-lg width-144">{{ i18n['下单时间'] }}</view>
						<view class="text-333">{{ model.create_time }}</view>
					</view>
					<view class="flex fu-fs24 padding-top align-center" v-if="model.pay_time">
						<view class="text-666 margin-right-lg width-144">优惠金额</view>
						<view class=" text-price">{{ model.coupon_money }}</view>
					</view>
					<view class="flex fu-fs24 padding-top align-center" v-if="model.pay_time">
						<view class="text-666 margin-right-lg width-144">积分抵扣金额</view>
						<view class=" text-price">{{ model.reduce_money }}</view>
					</view>
					<view class="flex fu-fs24 padding-top align-center" v-if="model.pay_time">
						<view class="text-666 margin-right-lg width-144">{{ i18n['付款金额'] }}</view>
						<view class="text-prices text-price">{{ model.payable_money }}</view>
					</view>
					<view class="flex fu-fs24 padding-top align-center" v-if="model.pay_type">
						<view class="text-666 margin-right-lg width-144">{{ i18n['支付方式'] }}</view>
						<view class="text-333">{{ model.pay_type}}</view>
					</view>
					<view class="flex fu-fs24 padding-top align-center" v-if="model.pay_time">
						<view class="text-666 margin-right-lg width-144">{{ i18n['支付时间'] }}</view>
						<view class="text-333">{{ model.pay_time ? model.pay_time : i18n['暂无'] }}</view>
					</view>
					<view class="flex fu-fs24 padding-top align-center" v-if="model.valid_time">
						<view class="text-666 margin-right-lg width-144">过期时间</view>
						<view class="text-333">{{ model.valid_time ? model.valid_time : i18n['暂无'] }}</view>
					</view>
				</view>
			</view>
			<!-- 拼团商品的信息 -->
			<view class="margin-sm" v-if="order_type == 5">
				<view class="bg-white radius-20 text-df text-333 padding-lr-sm padding-bottom">
					<view class="title-block text-lg text-blod flex align-center padding-top">{{ i18n['拼团明细'] }}</view>
					<view class="content">
						<view class="info-item flex text-sm padding-top">
							<view class="text-gray margin-right-sm">{{ i18n['开团时间'] }}:</view>
							<view class="text-333">{{ model.group_info.create_time }}</view>
						</view>
						<view class="info-item flex text-sm padding-top">
							<view class="text-gray margin-right-sm">{{ i18n['是否成团'] }}:</view>
							<view class="text-333">{{ model.group_info.is_full == 1 ? i18n['是'] : i18n['否'] }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 订单信息-结束 -->
		<view class="bottom flex align-center justify-center margin-top-32">
			<view class="line"></view>
			<image src="https://localelife.chunchuangkeji.cn/h5img/images/star-3.png" class="fu-block-24 margin-lr-24"></image>
			<view class="line"></view>
		</view>
		<!-- 底部操作-开始 -->
		<view class="footer-wrap bg-white" v-if="isContentShow([3,4,5,6,10], model.order_type)">
			<view class="footer-wrap-btn flex align-center justify-end height-100 padding-lr">
				<view
					class="round width-144 height-56 line-height-56 fu-fs24 margin-right-sm text-center bg-f6 text-333 btn"
					@tap.stop="showPopup = true" v-if="isContentShow([0], model.status)">
					{{ i18n['取消订单'] }}
				</view>
				<view
					class="round width-144 height-56 line-height-56 fu-fs24 margin-right-sm text-center bg-theme text-white btn"
					@tap.stop="toPay(order_sn, order_type)" v-if="isContentShow([0], model.status)">
					{{ i18n['去付款'] }}
				</view>
				<!-- <view
					class="round width-144 height-56 line-height-56 fu-fs24 margin-right-sm text-center bg-f6 text-333 btn"
					@tap.stop="delOrder" v-if="isContentShow([-2, -1, 4, 6, 7], model.status)">
					{{ i18n['删除订单'] }}
				</view> -->
				<!-- <view
					class="round width-170 height-60 fu-fs24 margin-right-sm text-center line-height-60 bg-f6 text-333 btn"
					@tap.stop="seelogs" v-if="isContentShow([2], model.status) && model.send_type != 1">
					{{ i18n['查看物流'] }}
				</view> -->
				<view
					class="round width-144 height-56 line-height-56 fu-fs24 margin-right-sm text-center bg-theme text-white btn"
					@click.stop="evaluateOrder()" v-if="isContentShow([3], model.status)">
					去评价
				</view>
				<view
					class="round width-144 height-56 line-height-56 fu-fs24 margin-right-sm text-center bg-theme text-white btn"
					@click.stop="toAftermarket()" v-if="isContentShow([1], model.status)">
					申请退款
				</view>
				<!-- <view
					class="round width-144 height-56 line-height-56 fu-fs24 margin-right-sm text-center bg-theme text-white btn"
					@tap.stop="remindOrder(order_sn)"
					v-if="select_way_num == 1 && isContentShow([1], model.status) && model.is_remind.info == 0 && (order_type != 7 || model.final_status == 1) && (order_type != 5 || model.group_info.is_full == 1)">
					{{ i18n['提醒发货'] }}
				</view>
				<view
					class="round width-170 height-60 fu-fs24 margin-right-sm text-center line-height-60 bg-theme text-white btn"
					style="opacity: 0.7;"
					v-if="select_way_num == 1 && isContentShow([1], model.status) && model.is_remind.info == 1 && (order_type != 7 || model.final_status == 1) && (order_type != 5 || model.group_info.is_full == 1)">
					{{ i18n['已提醒'] }}
				</view> -->
				<!-- <view class="" v-if="model.order_type == 5">
					<template
						v-if="model.group_info.is_full == 0 && model.order_type != 5 || model.group_info.is_full == 1 && model.order_type == 5">
						<view
							class="round width-144 height-56 line-height-56 fu-fs24 margin-right-sm text-center bg-theme text-white btn"
							@tap.stop="receiveOrder" v-if="isContentShow([2], model.status)">
							{{ i18n['确认收货'] }}
						</view>
					</template>
				</view>
				<view class="" v-else>
					<view
						class="round width-144 height-56 line-height-56 fu-fs24 margin-right-sm text-center bg-theme text-white btn"
						@tap.stop="receiveOrder" v-if="isContentShow([2], model.status)">
						{{ i18n['确认收货'] }}
					</view>
				</view> -->
			</view>
		</view>
		<!-- 底部操作-结束 -->

		<!-- 取消订单弹出层-开始 -->
		<fu-popup v-model="showPopup" mode="bottom" border-radius="24">
			<view class="bg-white">
				<view class="flex justify-between align-center padding-lr padding-top fu-fs32">
					<view class="text-bf" @click="showPopup = false">{{ i18n['取消'] }}</view>
					<view class="text-bold fu-fs36 text-333">{{ i18n['取消订单'] }}</view>
					<view class="text-theme" @click="cancelOrder()">{{ i18n['确定'] }}</view>
				</view>
				<view class="margin-top">
					<view class="fu-fs28 text-666 bg-f8 padding-lr padding-tb-sm">{{ i18n['请选择取消订单原因'] }}</view>
					<scroll-view scroll-y="true" class="padding-tb" style="max-height: 400rpx; min-height: 200rpx">
						<view class="padding-lr">
							<view @click="onChangeReson(item, index)"
								class="flex align-center justify-between padding-bottom"
								v-for="(item, index) in reasonList" :key="index">
								<view class="text-333 fu-fs32">{{ item.reason }}</view>
								<image class="fu-block-32" v-if="index == cancelReason.current"
									:src="imgBaseUrl + 'checked.png'" mode="aspectFit"></image>
								<image class="fu-block-32" v-else :src="imgBaseUrl + 'unchecked.png'"
									mode="aspectFit"></image>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</fu-popup>
		<!-- 取消订单弹出层-结束 -->
	</view>
</template>

<script>
	const statusObj = {
		'-1': global.i18n['已取消'],
		0: global.i18n['等待买家付款中'],
		1: global.i18n['订单已付款，等待卖家发货'],
		2: global.i18n['卖家已发货'],
		3: global.i18n['交易成功'],
		4: global.i18n['订单已评价'],
		5: global.i18n['售后处理中'],
		6: global.i18n['退款成功']
	};
	import {
		IMG_BASE_URL,
		product_host,
		BASE_URL
	} from '@/common/config.js'
	export default {
		data() {
			return {
				downTime: {
					days: 0,
					hours: 0,
					minutes: 0,
					seconds: 0
				},
				timer: null, // 定时器
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				isShowLoading: true,
				showPopup: false, // 控制取消订单弹出层是否显示
				order_sn: '', //订单号，订单列表页面传过来
				status: '', //订单状态，-1：已取消 0：待付款 1：待发货 2：待收货 3：交易成功
				order_type: '', //订单类型, 3：普通订单
				itemIndex: null, //当前订单在订单列表页的索引
				model: {
					is_refund: true, //针对完成的单据是否显示去评价（完成退款售后不显示）
					//订单详情对象
					create_time: '', //创建时间
					status: null, //订单状态，-1：已取消 0：待付款 1：待发货 2：待收货 3：交易成功
					order_sn: null, //订单号
					user_id: '', //会员id
					order_type: 3, //订单类型, 3：普通订单 4：积分订单 5：拼团订单 6：秒杀订单 7：预售订单 10抢购
					order_money: '', //订单金额
					payable_money: '', //应付金额
					real_money: '', //实付金额
					real_balance: '', //真实金额
					pay_status: '', //支付状态
					pay_type: '', //支付渠道
					coupon_id: '', //优惠券id
					coupon_money: '', //优惠券金额
					transaction_id: '', //第三方支付订单id
					pay_time: '', //支付时间
					return_id: '', //取消订单原因
					sender_id: '', //发货人ID
					activity_time: {
						presell_stime: '',
						presell_etime: '',
						is_pay: ''
					}, // 预售信息
					final_status: '', // 尾款状态
					final_order: {
						payable_money: '', //尾款金额
						order_type: '',
						order_sn: ''
					},
					is_remind: {
						info: ''
					}, // 是否提醒
					group_info: {
						is_full: '',
						create_time: '' // 拼团信息
					},
					order_info: {
						address_id: '', //地址ID
						receiver_mobile: '', //接收人电话
						receiver_address: '', //接收人地址
						receiver_name: '', //接收人姓名
						remark: '', //备注
						consign_time: '', //卖家发货时间
						sign_time: '', //买家签收时间
						finish_time: '', //订单完成时间
						express_price: '', //运费
						province: '', //省
						city: '', //市
						district: '', //区
						label_name: '' // 标签名
					},
					pick_info: {
						pickup_date: '',
						pickup_delivery_time: '',
						deliver_mobile: '',
						deliver_name: '',
						full_address: ''
					},
					order_goods_list: [], //订单商品列表
					cancel_time: '', //取消时间
					refund_day: '', //拒绝日期
					order_refund_status: 0, //订单是进行售后是否已经完成
					invoice_status: 0, // 发票状态
				},
				reasonList: [], //取消原因列表
				cancelReason: {
					//取消原因对象
					current: -1, //当前原因索引
					id: '' //档原因id
				},
				goodsInfo: [], // 下单商品
				select_way_num: 1 //用来判断是配送订单  还是自取订单  1 是配送 默认 2是自取
			};
		},
		onLoad({
			order_sn,
			status,
			order_type,
			itemIndex
		}) {
			this.order_sn = order_sn;
			this.status = status;
			this.order_type = order_type;
			this.itemIndex = itemIndex;
			this.getReasonList();
			uni.$on('onOrederDetailPageUpdata', this.onOrederDetailPageUpdata);
		},
		onShow() {
			this.getDetail();
		},
		onUnload() {
			uni.$off('onOrederDetailPageUpdata');
		},
		computed: {
			userInfo() {
				return this.$store.getters.userInfo || {};
			}
		},
		methods: {
			save() {
				uni.getImageInfo({
					src: this.model.picke_code_img,
					success: (res) => {
						uni.saveImageToPhotosAlbum({
						  filePath: res.path,
						  success: (res) => {
						    this.$message.info('保存成功');
						  },
						  fail:(err)=>{
							  console.log(err)
						  	this.$message.info('保存失败')
						  }
						})
					}
				})
			},
			/**
			 * @description 去支付尾款
			 * @param {string} sn = 订单号
			 * @param {Number} type = 订单类型
			 * */
			toPayFinal() {
				if (this.model.final_order.can_pay == 0) return;
				this.$urouter.navigateTo({
					url: '/pages/order/order-process/pay-order/index',
					params: {
						order_sn: this.model.final_order.order_sn,
						order_type: this.model.final_order.order_type
					}
				});
			},
			navToDetail(item) {
				console.log("item: ", item);
				if (this.order_type == 3) {
					this.$urouter.navigateTo({
						url: '/pages/goods/goodsdetail/goods-detail/index',
						params: {
							sku_id: item.sku_id || 0,
							goods_id: item.goods_id,
							order_sn:item.order_sn
						}
					});
				} else {
					/**
					 * 获取活动商品是否下架 
					 */
					uni.showLoading({
						mask: true
					})
					console.log("item.activity_id: ", item.activity_id);
					this.$api.post(global.apiUrls.postActivitysStatus, {
						activity_id: item.activity_id,
						goods_id: item.goods_id
					}).then(res => {
						uni.hideLoading();
						if (res.data.code == 1) {
							let isTodetail = res.data.msg.status // 1 可以跳转商品详情 0 跳转普通商品详情
							if (isTodetail == 1) {
								if (this.order_type == 6) {
									// 秒杀 
									this.$urouter.navigateTo({
										url: '/pages/activity/seckill/seckill-detail/index',
										params: {
											sku_id: item.sku_id || 0,
											goods_id: item.goods_id,
											activity_id: item.activity_id
										}
									});
								} else if (this.order_type == 5) {
									// 拼团 
									this.$urouter.navigateTo({
										url: '/pages/activity/assemble/assemble-detail/index',
										params: {
											sku_id: item.sku_id || 0,
											goods_id: item.goods_id,
											activity_id: item.activity_id
										}
									});
								} else if (this.order_type == 7) {
									// 预售 
									this.$urouter.navigateTo({
										url: '/pages/activity/advance/advance-detail/index',
										params: {
											sku_id: item.sku_id || 0,
											goods_id: item.goods_id,
											activity_id: item.activity_id
										}
									});
								} else if (this.order_type == 10) {
									// 砍一刀
									this.$urouter.navigateTo({
										url: '/pages/activity/bargain/bargain-detail/index',
										params: {
											sku_id: item.sku_id || 0,
											goods_id: item.goods_id,
											activity_id: item.activity_id
										}
									});
								}
							} else {
								this.$message.info("商品已经下架了");
							}
						}
					})
				}
			},
			/**
			 * @event
			 * @description 跳转到商品详情
			 * @param {Object} item - 商品信息
			navToDetail1(item) {
				if (this.order_type == 5) {
					this.$urouter.navigateTo({
						url: "/pages/activity/assemble/assemble-detail/index",
						params: {
							goods_id: item.goods_id,
							sku_id: item.sku_id || 0,
							activity_id: item.activity_id || 0,
						},
					});
				} else {
					this.$urouter.navigateTo({
						url: '/pages/goods/goodsdetail/goods-detail/index',
						params: {
							sku_id: item.sku_id || 0,
							goods_id: item.goods_id
						}
					});
				}
			},			 */
			// 提醒发货
			remindOrder() {
				this.$api.post(global.apiUrls.postRemindShipment, {
					order_sn: this.order_sn
				}).then(res => {
					this.$message.info(this.i18n['已提醒,请耐心等待']);
					uni.$emit('onPageUpdata', {
						type: 2,
						index: this.itemIndex,
					});
					this.getDetail();
				}).catch(err => {
					console.log('err: ' + JSON.stringify(err));
				});
			},
			// 查看物流
			seelogs() {
				let that = this;
				this.$urouter.navigateTo({
					url: '/pages/order/orderdetail/express-delivery/index',
					params: {
						order_sn: that.order_sn
					}
				});
			},
			/**
			 * @description 去支付
			 * @param {string} sn = 订单号
			 * @param {Number} type = 订单类型
			 * */
			toPay(sn, type) {
				console.log(sn, type);
				this.$urouter.redirectTo({
					url: '/pages/order/order-process/pay-order/index',
					params: {
						order_sn: sn,
						order_type: type
					}
				});
			},
			// 联系客服
			toCustomer(item) {
				let data = {
					order_sn: this.order_sn,
					orderStatus: statusObj[this.model.status],
					createTime: this.model.create_time,
					goods_thumb: item.goods_thumb,
					goods_name: item.goods_name,
					goods_price: item.goods_money,
					goods_id: item.goods_id
				};

				if (this.model.send_type == 1) {
					data.user_name = this.model.pick_info.pickup_user_name;
					data.user_phone = this.model.pick_info.pickup_user_mobile;
					data.user_address = this.model.pick_info.full_address;
				} else {
					data.user_name = this.model.order_info.receiver_name;
					data.user_phone = this.model.order_info.receiver_mobile;
					data.user_address = this.model.order_info.receiver_address;
				}

				try {
					uni.setStorageSync('CustomerCacheData', data);
				} catch (err) {
					console.log(err);
				}
				this.$urouter.navigateTo({
					url: '/pages/service-message/service/service-detail/index',
					params: {
						kid: 1,
						goods_id: item.goods_id,
						activity_id: item.activity_id || 0
					}
				});
			},
			// 订单评价
			evaluateOrder() {
				uni.setStorageSync('order_goods_list', JSON.stringify(this.goodsInfo));
				this.$urouter.navigateTo({
					url: '/pages/order/evaluation/order-evaluation/index',
					params: {
						order_sn: this.order_sn,
						order_type: this.order_type
					}
				});
			},
			/**
			 * @description 监听页面更新的回调函数
			 * @param {Object} data = 页面更新需要的参数
			 */
			onOrederDetailPageUpdata(data) {
				this.getDetail();
			},

			/**
			 * @description 获取订单详情
			 */
			getDetail() {
				this.$api
					.post(global.apiUrls.getOrderDetail, {
						order_sn: this.order_sn,
						order_type: this.order_type
					})
					.then(res => {
						this.isShowLoading = false;
						let data = res.data;
						console.log('获取订单详情', data);
						if (data.code == 1) {
							if (data.data.send_type == 1) {
								this.select_way_num = 2;
							} else {
								this.select_way_num = 1;
							}
							this.model = data.data;
							this.goodsInfo = data.data.order_goods_list;

							if (data.data.order_type == 5 && data.data.group_info.end_time != 0) {
								this.initDownTime(data.data.group_info.end_time, 0);
							} else {
								if (data.data.cancel_time) {
									this.initDownTime(data.data.cancel_time, 0);
								}
								if (data.data.status == 2 && data.data.order_receive_time != 0) {
									this.initDownTime(data.data.order_receive_time, 1);
								}
							}
							//去评价 
							if (this.model.status == 3 && this.goodsInfo && this.goodsInfo.length > 0) {
								this.goodsInfo.forEach((goodItem) => {
									this.model.is_refund = false
									if (goodItem.order_refund_status || goodItem.order_refund_status == 0) {
										this.model.is_refund = true
									}
								})
							}
						}
					});
			},

			/**
			 * @description 获取取消原因列表
			 */
			getReasonList() {
				this.$api
					.post(global.apiUrls.getReasonList, {
						type: 2
					})
					.then(res => {
						let data = res.data;
						console.log('获取取消原因列表', data.data);
						if (data.code == 1) {
							this.reasonList = data.data;
						}
					});
			},
			onUnload() {
				clearInterval(this.timer);
				this.timer = null;
			},
			// 开启倒计时
			initDownTime(time, type) {
				if (this.timer) {
					clearInterval(this.timer);
				}
				let endTime = time;
				// let nowTime = new Date().getTime();
				// let timeleft = endTime - nowTime;
				this.timer = setInterval(() => {
					endTime--
					if (endTime > 0) {
						let hours = parseInt((endTime / (60 * 60)) % 24);
						let minutes = parseInt((endTime / 60) % 60);
						let seconds = parseInt(endTime % 60);
						let days = parseInt(endTime / 60 / 60 / 24); //计算剩余的天数
						this.downTime.days = days;
						this.downTime.hours = hours < 10 ? '0' + hours : hours;
						this.downTime.minutes = minutes < 10 ? '0' + minutes : minutes;
						this.downTime.seconds = seconds < 10 ? '0' + seconds : seconds;
					} else {
						clearInterval(this.timer);
						if (type == 0) {
							this.$api
								.post(global.apiUrls.postCancelOrderAuto, {
									order_sn: this.model.order_sn
								})
								.then(res => {
									let data = res.data;
									uni.hideLoading();
									this.$message.info(data.msg);
									if (data.code == 1) {
										// 更新列表页数据
										uni.$emit('onPageUpdata', {
											type: 1,
											index: this.itemIndex,
										});
									}
								});
						}
						this.getDetail();
						this.timer = null;
					}
				}, 1000);
			},
			// 去店铺
			goMerchant(item) {
				if (item.status == '0') return this.$message.info("该店铺已关闭");
				this.$urouter.navigateTo({
					url: '/pages/goods/shop/shop/index',
					params: {
						partner_id: item.u_id
					}
				});
			},
			/**
			 * @description 取消订单
			 */
			cancelOrder() {
				if (!this.cancelReason.id) return this.$message.info(this.i18n['请选择取消原因']);
				uni.showLoading({
					title: this.i18n['操作中'],
					mask: true
				});
				this.$api
					.post(global.apiUrls.postCancelOrder, {
						order_sn: this.model.order_sn,
						return_id: this.cancelReason.id
					})
					.then(res => {
						let data = res.data;
						uni.hideLoading();
						this.$message.info(data.msg);
						if (data.code == 1) {
							this.showPopup = false;
							this.getDetail();
							// 更新列表页数据
							uni.$emit('onPageUpdata', {
								type: 1,
								index: this.itemIndex,
							});
						}
					});
			},

			/**
			 * @description 删除订单
			 */
			delOrder() {
				this.$util.showModal({
					title: this.i18n['确认删除此订单?'],
					content: this.i18n['删除后不可恢复'],
					success: res => {
						if (res.confirm) {
							this.$api
								.post(global.apiUrls.postDelOrder, {
									order_sn: this.model.order_sn
								})
								.then(res => {
									let data = res.data;
									if (data.code == 1) {
										this.$message.info(this.i18n['删除成功']);
										setTimeout(() => {
											this.back();
											// 更新列表页数据
											uni.$emit('onPageUpdata', {
												type: 4,
												index: this.itemIndex,
											});
										}, 1000);
									} else {
										this.$message.info(data.msg);
									}
								})
								.catch(err => {
									console.log('err: ' + JSON.stringify(err));
								});
						}
					}
				});
			},

			/**
			 * @description 确认收货
			 * */
			receiveOrder() {
				this.$util.showModal({
					title: this.i18n['提示'],
					content: this.i18n['您是否确认收到货物?'],
					success: res => {
						if (res.confirm) {
							this.$api
								.post(global.apiUrls.postConfirmOrder, {
									order_sn: this.model.order_sn
								})
								.then(res => {
									let data = res.data;
									this.$message.info(data.msg);
									if (data.code == 1) {
										this.getDetail();
										// 更新列表页数据
										uni.$emit('onPageUpdata', {
											type: 3,
											index: this.itemIndex,
										});
									}
								})
								.catch(err => {
									console.log('err: ' + JSON.stringify(err));
								});
						}
					}
				});
			},

			/**
			 * @description 监听切换取消原因
			 * @param {Object} item = 当前原因项
			 * @param {Number} index = 当前原因在列表中的索引
			 */
			onChangeReson(item, index) {
				if (this.cancelReason.current == index) return false;
				this.cancelReason.current = index;
				this.cancelReason.id = item.id;
			},

			/**
			 * @description 去申请售后/售后详情
			 * @param {Object} item = 当前商品对象
			 * @param {Number} index = 当前商品在列表中的索引
			 */
			toAftermarket() {
				// uni.setStorageSync('afterorder_goods', JSON.stringify(item));
				this.$urouter.navigateTo({
					url: '/pages/order/afterorder/afterorder-apply/index',
					params: {
						order_sn: this.order_sn,
						back: 2
					}
				});
			},
			/**
			 * @description 去售后详情
			 * @param {Object} item = 当前商品对象
			 * @param {Number} index = 当前商品在列表中的索引
			 */
			toAfterOrderDetails(item, index) {
				this.$urouter.navigateTo({
					url: '/pages/order/afterorder/afterorder-detail/index',
					params: {
						order_sn: this.model.order_sn
					}
				});
			},
			/**
			 * @description 页面返回
			 * @param {delta} delta = 返回的页面数，如果 delta 大于现有页面数，则返回到首页
			 */
			back() {
				uni.navigateBack();
			},

			toShare() {
				let goods_name = this.model.order_goods_list[0].goods_name,
					goods_id = this.model.order_goods_list[0].goods_id,
					group_id = this.model.group_info.id,
					activity_id = this.model.group_info.activity_id,
					goods_thumb = this.model.order_goods_list[0].goods_thumb,
					phone = this.userInfo._mobile,
					invite_code = this.userInfo.invite_code
				console.log('888000', BASE_URL + '/register/h5/#/pages/assemble-detail/index?user_id=' + this.userInfo.id +
					'&phone=' + phone + '&invite_code=' + invite_code + '&type=assemable&goods_id=' + goods_id +
					'&activity_id=' + activity_id + '&group_id=' + group_id);
				uni.share({
					provider: 'weixin',
					type: '0',
					title: this.i18n['我发起了一个拼团'] + goods_name + ',' + this.i18n['赶快来参加~'],
					scene: 'WXSceneSession',
					href: BASE_URL + '/register/h5/#/pages/assemble-detail/index?user_id=' + this.userInfo.id +
						'&phone=' + phone + '&invite_code=' + invite_code + '&type=assemable&goods_id=' +
						goods_id + '&activity_id=' + activity_id + '&group_id=' + group_id,
					imageUrl: goods_thumb,
					success: (res) => {
						console.log("1111", res);
					},
					fail: (err) => {
						console.log('222222', err)
					}
				})
			},

			/**
			 * @description 判断内容是否显示
			 * @param {String} arr = 要判断的数组
			 * @param {String | Number} val = 要判的值
			 */
			isContentShow(arr, val) {
				return arr.includes(val * 1);
			},

			/**
			 * @description 复制订单号
			 * @param {String} orderSn = 订单号
			 */
			copyOrderSn(orderSn) {
				uni.setClipboardData({
					data: orderSn,
					success: () => {
						this.$message.info(this.i18n['复制成功']);
					}
				});
			},
			// 发票
			handleInvoice() {
				const {
					invoice_status,
					order_sn,
					payable_money
				} = this.model;
				let url =
					`/pages/invoice/invoice/apply-invoice/index?itemIndex=${this.itemIndex}&order_sn=${order_sn}&payable_money=${payable_money}&status=${invoice_status}`;
				// status == 0去申请开票
				if (invoice_status == 0) {
					uni.navigateTo({
						url: url
					});
				}
				// status == 1已申请过发票  可以修改发票（修改，撤销发票）   只有查看了发票才知道是否需要修改
				//  status == 2发票已经开票成功  不能再修改
				if (invoice_status == 1 || invoice_status == 2) {
					uni.navigateTo({
						url: '/pages/invoice/invoice/invoice-info/index?order_sn=' + order_sn + '&payable_money=' +
							payable_money
					});
				}
			},
		},
		filters: {
			// 过滤订单状态
			statusFil(val) {
				let data = {
					'status_-2': global.i18n['订单已取消'],
					'status_-1': '已取消',
					'status_-4': '已过期',
					'status_0': '待付款',
					'status_1': '待使用',
					'status_2': global.i18n['订单待收货'],
					'status_3': '已核销',
					'status_4': '已完成',
					'status_6': global.i18n['售后已完成'],
				};
				return data['status_' + val] || '';
			},
			// 过滤自取订单状态
			inviteStatusFil(val) {
				let data = {
					'status_-2': global.i18n['订单已取消'],
					'status_-1': global.i18n['交易关闭'],
					'status_-4': '已过期',
					'status_0': global.i18n['订单待付款'],
					'status_1': global.i18n['待提货'],
					'status_2': global.i18n['待提货'],
					'status_3': global.i18n['提货成功'],
					'status_4': global.i18n['订单已评价']
				};
				return data['status_' + val] || '';
			},
			// 过滤订单状态图标
			statusIconFil(val) {
				switch (val) {
					case -2:
						return IMG_BASE_URL + 'order/status_-2.png';
					case -1:
						return IMG_BASE_URL + 'order/status_-1.png';
					case 0:
						return IMG_BASE_URL + 'order/status_0.png';
					case 1:
						return IMG_BASE_URL + 'status_1.png';
					case 2:
						return IMG_BASE_URL + 'order/status_2.png';
					case 3:
						return IMG_BASE_URL + 'order/status_3.png';
					case 4:
						return IMG_BASE_URL + 'order/status_4.png';
					case 6:
						return IMG_BASE_URL + 'order/status_4.png';
					default:
						return '';
				}
			},
			// 过滤支付渠道
			payTypeFil(val) {
				let data = {
					wxpay: global.i18n['微信支付'],
					alipay: global.i18n['支付宝支付'],
					appleiap: global.i18n['苹果内购'],
					balance: global.i18n['余额支付'],
					minipay: global.i18n['小程序支付'],
					minipay_mix: global.i18n['组合支付'],
					xx_pay: global.i18n['后台下单']
				};
				return data[val] || '';
			}
		}
	};
</script>

<style lang="scss" scoped>
	page {
		background-color: #f8f8f8;

		.pages {
			padding-bottom: 120rpx;
			padding-bottom: calc(120rpx + constant(safe-area-inset-bottom));
			padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
		}

		.header-bg {
			background-image: url($IMG_BASE_URL + 'order-bg.png');
			background-repeat: no-repeat;
			background-size: 100%;
		}

		.address-tag {
			// min-width: 56rpx;
			// min-height: 34rpx;
			border-radius: 8rpx;
			font-size: 24rpx;
			padding: 6rpx 10rpx;
			color: $theme;
			background: $bgthemeOpacity;
			border: 1rpx solid $theme;
			margin-right: 16rpx;
		}

		.footer-wrap {
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			// bottom: constant(safe-area-inset-bottom);
			// bottom: env(safe-area-inset-bottom);
			padding-bottom: 0;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
			z-index: 999;

			.btn {
				&:last-child {
					margin-right: 0;
				}
			}
		}
	}

	.iconBox {
		position: absolute;
		left: 0;
		top: 0;
		border-radius: 16rpx 0 16rpx 0;
		z-index: 99;
	}

	/* 店铺 */
	.shop-box {
		padding: 24rpx 32rpx;
		background: linear-gradient(90deg, #FFEAE0 0%, rgba(255, 234, 224, 0) 100%);
		border-radius: 8rpx 8rpx 0 0;
	}

	.merchant-title {
		margin: 0rpx 0 32rpx;
	}

	.merchant-icon {
		width: 40rpx;
		height: 40rpx;
		margin-left: 0rpx;
		margin-right: 16rpx;
		top: 2rpx;
	}

	.merchant-icon-left {
		margin-left: 16rpx;
		font-size: 24rpx;
	}
	.show {
		.goods-box {
			border-bottom: 1rpx solid #eee;
			&:nth-last-of-type(1) {
				border-bottom: none;
			}
		}
	}
	.hxm {
		padding: 20rpx 26rpx;
		border-radius: 16rpx;
		background: rgba(220,170,57,0.08);
		margin-top: 24rpx;
	}
	.hx-code {
		background-color: #F6F7F9;
		border-radius: 8rpx;
		padding: 42rpx 0;
		margin-top: 16rpx;
		.btn {
			width: 302rpx;
			height: 72rpx;
			border-radius: 40rpx;
			border: 1rpx solid #FF6229;
			box-sizing: border-box;
			text-align: center;
			line-height: 72rpx;
			background-color: #fff;
			font-size: 28rpx;
			color: #FF6F27;
		}
	}
	.bottom {
		.line {
			width: 240rpx;
			height: 1rpx;
			background-color: #eee;
		}
	}
</style>
